<?php

namespace App\Services\Goods;


use App\Models\Goods\Brand;
use App\Services\BaseService;

class BrandService extends BaseService
{
    /**
     * 根据ID获取品牌
     * @param  int  $id
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
     */
    public function getBrand(int $id)
    {
        return Brand::query()
            ->where('id', $id)
            ->where('deleted', 0)
            ->first();
    }

    /**
     * 获取品牌列表
     * @param  int  $page
     * @param  int  $limit
     * @param $sort
     * @param $order
     * @param  string[]  $cloumn
     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
     */
    public function getBrandList(int $page, int $limit, $sort, $order, $cloumn = ['*'])
    {
        $query = Brand::query()->where('deleted', 0);
        if (!empty($sort) && !empty($order)) {
            $query->orderBy($sort, $order);
        }
        return $query->paginate($limit, $cloumn, 'page', $page);
    }

}
